package com.situ.company.web220111.project.service.impl;

import com.situ.company.web220111.project.dao.IProjectDao;
import com.situ.company.web220111.project.dao.impl.ProjectDaoImpl;
import com.situ.company.web220111.project.model.ProjectModel;
import com.situ.company.web220111.project.service.IProjectService;

import java.util.List;


public class ProjectServiceImpl implements IProjectService {

    IProjectDao dao = new ProjectDaoImpl();

    @Override
    public String insert(ProjectModel model) {
        ProjectModel m1 = new ProjectModel(model.getCode());
        ProjectModel mdb = dao.selectModel(m1);
        if (mdb != null) return "repeat";
        return dao.insert(model) + "";
    }

    @Override
    public String delete(ProjectModel model) {
        return dao.deleteByCode(model) + "";
    }

    @Override
    public String update(ProjectModel model) {
        return dao.updateActive(model) + "";
    }

    @Override
    public List<ProjectModel> selectList(ProjectModel model) {
        String code = model.getCode();
        model.setCode(code == null ? "%" : "%" + code + "%");
        String name = model.getName();
        model.setName(name == null ? "%" : "%" + name + "%");
        return dao.selectList(model);
    }

    @Override
    public ProjectModel selectModel(ProjectModel model) {
        ProjectModel mdb = new ProjectModel();
        mdb.setCode(model.getCode());
//		mdb.setName(model.getName());
        return dao.selectModel(mdb);
    }

    @Override
    public Integer selectCount(ProjectModel model) {
        ProjectModel mdb = new ProjectModel();
        mdb.setCode(model.getCode() == null ? "" : "%" + model.getCode() + "%");
        mdb.setName(model.getName() == null ? "" : "%" + model.getName() + "%");
        return dao.selectCount(mdb);
    }


}
